package util

type CountDownLatch struct {
	count    int
	boolChan chan bool
}

func NewCountDownLatch(count int) *CountDownLatch {
	var countDownLatch CountDownLatch
	countDownLatch.count = count
	countDownLatch.boolChan = make(chan bool, count)
	return &countDownLatch
}

func (countDownLatch *CountDownLatch) CountDown() {
	countDownLatch.boolChan <- true
}

func (countDownLatch *CountDownLatch) Await() {
	var i int = 0
	for _ = range countDownLatch.boolChan {
		i++
		if i >= countDownLatch.count {
			break
		}
	}
	close(countDownLatch.boolChan)
}
